package main

import (
	"net/http"
	"strconv"
	"time"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
		})
	})

	r.GET("/echoWithSleepMS", func(c *gin.Context) {
		sleepMs := c.Query("sleepMS")
		echo := c.Query("echo")
		if sleepMs != "" {
			timeMs, err := strconv.ParseInt(sleepMs, 10, 64)
			if err == nil {
				time.Sleep(time.Duration(timeMs) * time.Millisecond)
			}
		}
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
			"echo": echo,
		})
	})

	r.Run(":9999")
}
